#include "Statistics.h"
#include <fstream>
#include <string>
#include <iostream>
#include "Util.h"
using namespace U32;
Statistics::Statistics(void)
{
	wageArray.fill(0);
}

	void Statistics::readFromFile(){
		std::ifstream file = std::ifstream("salary.txt");
		while (file.good()){
			std::string s = util::readLine(&file);
			int i = atoi(s.c_str());
			if (i >= 20000 && i <= 1000000){
				wageArray[i]++;
			}
		}
	}
	
	long long Statistics::calculate_mean(){
		
		int count = 0;
		for (int i = 0; i < 1000000; i++){
			count += wageArray[i];
		}
		long long sum = 0;
		for (int i = 0; i < 1000000; i++){
			sum += wageArray[i] * i;
		}
		return sum/count;
	}
	int Statistics::calculate_median(){
		int count = 0;
		for (int i = 0; i < 1000000; i++){
			count += wageArray[i];
		}
		int count2 = 0, i = 0;
		while (count2 <= count/2){
			count2 += wageArray[i];
			i++;
		}
		return i;
	}

Statistics::~Statistics(void)
{
}
void U32::main_one(){
	Statistics s = Statistics();
	s.readFromFile();
	std::cout << s.calculate_mean() << std::endl;
	std::cout << s.calculate_median() << std::endl;
}